﻿Imports System.Data
Imports Oracle.DataAccess.Client
Imports Oracle.DataAccess.Types

Public Class ResellAdd

    Dim objConn As OracleConnection
    Dim cmd As OracleCommand
    Dim dtadapter As OracleDataAdapter
    Dim da As OracleDataAdapter
    Dim cb As OracleCommandBuilder
    Dim Udone As New Err
    Dim Done As New Done
    Dim infor As New infor
    Dim ds As DataSet

    Private Sub BT1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BT1.Click
        Me.Close()
    End Sub

    Private Sub ADD1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ADD1.Click
        If TextBox1.Text = "" Or textbox3.Text = "" Or Textbox4.Text = "" Or TextBox5.Text = "" Or TextBox6.Text = "" Then
            infor.ShowDialog()
        Else
            Dim strConnString As String = Login.strConn
            objConn = New OracleConnection(strConnString)
            Dim cmd As New OracleCommand
            Dim str1 As String = ""
            Dim str3 As String = ""
            Dim str4 As String = ""
            Dim str5 As String = ""
            Dim str6 As String = ""
            Dim str7 As String = ""

            str1 = TextBox1.Text
            str3 = DateTimePicker1.Value
            str4 = textbox3.Text
            str5 = Textbox4.Text
            str6 = TextBox5.Text
            str7 = TextBox6.Text

            Try
                Dim sql As String = "Insert into BILL_SELL VALUES('" + str1 + "','" + str3 + "','" + str4 _
                                    + "','" + str5 + "','" + str6 + "','" + str7 + "')"
                objConn.Open()
                With cmd
                    .Connection = objConn
                    .CommandText = sql
                    .CommandType = CommandType.Text
                End With
                Try
                    cmd.ExecuteNonQuery()
                    Done.ShowDialog()
                Catch ex As Exception
                    Udone.ShowDialog()
                End Try
            Catch ex As Exception
                Udone.ShowDialog()
            Finally
                objConn.Close()
                TextBox1.Text = ""
                TextBox5.Text = ""
                TextBox6.Text = ""
                DateTimePicker1.Value = Today
                DATASC()
                textbox3.Text = ""
                Textbox4.Text = ""
            End Try
        End If
    End Sub

    Private Sub ResellAdd_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        DATASC()
        textbox3.Text = ""
        Textbox4.Text = ""
    End Sub

    Private Sub DATASC()
        Dim strConnString As String
        strConnString = Login.strConn
        objConn = New OracleConnection(strConnString)
        objConn.Open()
        Dim cmd2 As New OracleCommand
        Dim sql1 As String = "select * from LOTS ORDER BY MED_ID ASC"
        cmd2 = New OracleCommand(sql1, objConn)
        da = New OracleDataAdapter(cmd2)
        cb = New OracleCommandBuilder(da)
        ds = New DataSet()
        da.Fill(ds, "LOTS")

        With Me.Textbox4
            .DataSource = ds.Tables("LOTS")
            .DisplayMember = "LOT_NO"
            .ValueMember = "LOT_NO"
        End With

        Dim sql2 As String = "select * from MEDICINES ORDER BY MED_ID ASC"
        cmd2 = New OracleCommand(sql2, objConn)
        da = New OracleDataAdapter(cmd2)
        cb = New OracleCommandBuilder(da)
        ds = New DataSet()
        da.Fill(ds, "MEDICINES")

        With Me.textbox3
            .DataSource = ds.Tables("MEDICINES")
            .DisplayMember = "MED_NAME"
            .ValueMember = "MED_ID"
        End With
    End Sub
End Class